cap program drop word_orderer
program define word_orderer
	args dem_vars
	gen orderer = 0
	local i = 0
	foreach w in `dem_vars' {
		replace  orderer = `i' if dem_var == "`w'"
		local i = `i' + 1
	}
	sort orderer
	drop orderer
end

cap program drop drop_ind_sd
program define drop_ind_sd
	args dem_vars js
	foreach w in `dem_vars' { 
		foreach j in `js' {
			di "`w'"
			replace sd_`j' = . if dem_var == "`w'" & strpos("`w'", "_ind") 
			replace p50_`j' = . if  dem_var == "`w'" &  strpos("`w'", "_ind") 
		}
	}
end

cap program drop set_grstyle
program define set_grstyle
	grstyle init
	grstyle set plain
	graph set eps fontface Times
	grstyle set size vlarge: axis_title
	grstyle set size large: tick_label
end

cap program drop colorpalette_metal
program colorpalette_metal
	c_local P #D65942, #38C1D6, #8A671D
	c_local class qualitative
end

cap program drop colorpalette_market
program colorpalette_market
	c_local P dkorange, dknavy
	c_local class qualitative
end

cap program drop gen_bool
program define gen_bool
	args v
	tempvar bool
	gen `bool' = (`v' == "TRUE")
	drop `v'
	gen `v' = `bool'
end 
